# ****************************************************
# “Measuring Time Preferences in Large Surveys”
# 
# Bechtel, Michael M.
# Jensen, Amalie
# McAllister, Jordan H.
# Scheve, Kenneth F. 

# REPLICATION ARCHIVE 

# ********** DATA CITATION DISCLAIMER **************
#   Use of this replication archive (in full or in part) is subject to data citation requirements: Data Citation Synthesis Group: Joint Declaration of Data Citation Principles. Martone M. (ed.) San Diego CA: FORCE11; 2014 https://doi.org/10.25490/a97f-egyk
# **************************************************
setwd("~/Desktop/Dropbox/Climate fairness/11 Replication Archives/03 Replication PSRM/")
#read in full data
ctbdata_all <- read.csv("02 Data/ltpublicpolicy.csv", stringsAsFactors=FALSE)

#sociodemographics
##education (binary for less_high, high, some_college, and BA_plus)
ctbdata_all$Education[which(ctbdata_all$Education == "No schooling completed, or less than 1 year")] <- 1
ctbdata_all$Education[which(ctbdata_all$Education == "Nursery, kindergarten, and elementary (grades 1-8)")] <- 1
ctbdata_all$Education[which(ctbdata_all$Education == "High school (grades 9-12, no degree)")] <- 1
ctbdata_all$Education[which(ctbdata_all$Education == "High school graduate (or equivalent)")] <- 2
ctbdata_all$Education[which(ctbdata_all$Education == "Some college (1-4 years, no degree)")] <- 3
ctbdata_all$Education[which(ctbdata_all$Education == "Associate’s degree (including occupational or academic degrees)")] <- 3
ctbdata_all$Education[which(ctbdata_all$Education == "Bachelor’s degree (BA, BS, AB, etc)")] <- 4
ctbdata_all$Education[which(ctbdata_all$Education == "Master’s degree (MA, MS, MENG, MSW, etc)")] <- 4
ctbdata_all$Education[which(ctbdata_all$Education == "Professional school degree (MD, DDC, JD, etc)")] <- 4
ctbdata_all$Education[which(ctbdata_all$Education == "Doctorate degree (PhD, EdD, etc)")] <- 4
ctbdata_all$Education <- as.numeric(ctbdata_all$Education)
ctbdata_all$Less.high <- ctbdata_all$Education
ctbdata_all$Less.high[which(ctbdata_all$Less.high != 1)] <- 0
ctbdata_all$Less.high[which(ctbdata_all$Less.high == 1)] <- 1
ctbdata_all$Less.high <- as.factor(ctbdata_all$Less.high)
ctbdata_all$High <- ctbdata_all$Education
ctbdata_all$High[which(ctbdata_all$High != 2)] <- 0
ctbdata_all$High[which(ctbdata_all$High == 2)] <- 1
ctbdata_all$High <- as.factor(ctbdata_all$High)
ctbdata_all$Some.college <- ctbdata_all$Education
ctbdata_all$Some.college[which(ctbdata_all$Some.college != 3)] <- 0
ctbdata_all$Some.college[which(ctbdata_all$Some.college == 3)] <- 1
ctbdata_all$Some.college <- as.factor(ctbdata_all$Some.college)
ctbdata_all$BA.plus <- ctbdata_all$Education
ctbdata_all$BA.plus[which(ctbdata_all$BA.plus != 4)] <- 0
ctbdata_all$BA.plus[which(ctbdata_all$BA.plus == 4)] <- 1
ctbdata_all$BA.plus <- as.factor(ctbdata_all$BA.plus)
##white (binary)
ctbdata_all$White <- ctbdata_all$Race
ctbdata_all$White[which(ctbdata_all$White == "White")] <- 1
ctbdata_all$White[which(ctbdata_all$White == "Black or African American")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Hispanic or Latino")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Asian or Asian-American")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Native American")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Middle Eastern")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Mixed Race")] <- 0
ctbdata_all$White[which(ctbdata_all$White == "Other")] <- 0
ctbdata_all$White <- as.factor(ctbdata_all$White)
##female (binary)
ctbdata_all$Female <- ctbdata_all$Gender
ctbdata_all$Female[which(ctbdata_all$Female == "Female")] <- 1
ctbdata_all$Female[which(ctbdata_all$Female == "Male")] <- 0
ctbdata_all$Female[which(ctbdata_all$Female == "Other")] <- 0
ctbdata_all$Female <- as.factor(ctbdata_all$Female)
##hhi (binary for low_inc, lowmid_inc, uppmid_inc, and high_inc)
ctbdata_all$HHI[which(ctbdata_all$HHI == "Under $10,000")] <- 1
ctbdata_all$HHI[which(ctbdata_all$HHI == "$10,000 - $19,999")] <- 1
ctbdata_all$HHI[which(ctbdata_all$HHI == "$20,000 - $29,999")] <- 2
ctbdata_all$HHI[which(ctbdata_all$HHI == "$30,000 - $39,999")] <- 2
ctbdata_all$HHI[which(ctbdata_all$HHI == "$40,000 - $54,999")] <- 3
ctbdata_all$HHI[which(ctbdata_all$HHI == "$55,000 - $69,999")] <- 3
ctbdata_all$HHI[which(ctbdata_all$HHI == "$70,000 - $84,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$85,000 - $99,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$100,000 - $124,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$125,000 - $149,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$150,000 - $174,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$175,000 - $199,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$200,000 - $249,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$250,000 - $349,999")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "$350,000 - $470,000")] <- 4
ctbdata_all$HHI[which(ctbdata_all$HHI == "Over $470,000")] <- 4
ctbdata_all$HHI <- as.numeric(ctbdata_all$HHI)
ctbdata_all$Low.inc <- ctbdata_all$HHI
ctbdata_all$Low.inc[which(ctbdata_all$Low.inc != 1)] <- 0
ctbdata_all$Low.inc[which(ctbdata_all$Low.inc == 1)] <- 1
ctbdata_all$Low.inc <- as.factor(ctbdata_all$Low.inc)
ctbdata_all$LowMid.inc <- ctbdata_all$HHI
ctbdata_all$LowMid.inc[which(ctbdata_all$LowMid.inc != 2)] <- 0
ctbdata_all$LowMid.inc[which(ctbdata_all$LowMid.inc == 2)] <- 1
ctbdata_all$LowMid.inc <- as.factor(ctbdata_all$LowMid.inc)
ctbdata_all$UppMid.inc <- ctbdata_all$HHI
ctbdata_all$UppMid.inc[which(ctbdata_all$UppMid.inc != 3)] <- 0
ctbdata_all$UppMid.inc[which(ctbdata_all$UppMid.inc == 3)] <- 1
ctbdata_all$UppMid.inc <- as.factor(ctbdata_all$UppMid.inc)
ctbdata_all$High.inc <- ctbdata_all$HHI
ctbdata_all$High.inc[which(ctbdata_all$High.inc != 4)] <- 0
ctbdata_all$High.inc[which(ctbdata_all$High.inc == 4)] <- 1
ctbdata_all$High.inc <- as.factor(ctbdata_all$High.inc)
##age (binary for young, mid_young, mid_old, and old)
ctbdata_all$Born[which(ctbdata_all$Born <= 1957)] <- 4
ctbdata_all$Born[which((ctbdata_all$Born <= 1972) & ctbdata_all$Born > 1957)] <- 3
ctbdata_all$Born[which((ctbdata_all$Born <= 1987) & ctbdata_all$Born > 1972)] <- 2
ctbdata_all$Born[which(ctbdata_all$Born > 1987)] <- 1
ctbdata_all$Born <- as.numeric(ctbdata_all$Born)
ctbdata_all$Young <- ctbdata_all$Born
ctbdata_all$Young[which(ctbdata_all$Young != 1)] <- 0
ctbdata_all$Young[which(ctbdata_all$Young == 1)] <- 1
ctbdata_all$Young <- as.factor(ctbdata_all$Young)
ctbdata_all$Mid.Young <- ctbdata_all$Born
ctbdata_all$Mid.Young[which(ctbdata_all$Mid.Young != 2)] <- 0
ctbdata_all$Mid.Young[which(ctbdata_all$Mid.Young == 2)] <- 1
ctbdata_all$Mid.Young <- as.factor(ctbdata_all$Mid.Young)
ctbdata_all$Mid.Old <- ctbdata_all$Born
ctbdata_all$Mid.Old[which(ctbdata_all$Mid.Old != 3)] <- 0
ctbdata_all$Mid.Old[which(ctbdata_all$Mid.Old == 3)] <- 1
ctbdata_all$Mid.Old <- as.factor(ctbdata_all$Mid.Old)
ctbdata_all$Old <- ctbdata_all$Born
ctbdata_all$Old[which(ctbdata_all$Old != 4)] <- 0
ctbdata_all$Old[which(ctbdata_all$Old == 4)] <- 1
ctbdata_all$Old <- as.factor(ctbdata_all$Old)

#understanding check 
##relation (correct answer denoted by 1)
ctbdata_all$Relation[which(ctbdata_all$Relation == "As the sooner payment goes down, the later payment stays the same.")] <- 0
ctbdata_all$Relation[which(ctbdata_all$Relation == "As the sooner payment goes down, the later payment goes down.")] <- 0
ctbdata_all$Relation[which(ctbdata_all$Relation == "The sooner and the later payment are always the same.")] <- 0
ctbdata_all$Relation[which(ctbdata_all$Relation == "As the sooner payment goes down, the later payment goes up.")] <- 1
##today (correct answer denoted by 1)
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 0
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $3.80
and payment in 5 WEEKS of $16.00")] <- 0
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $7.60
and payment in 5 WEEKS of $12.00")] <- 0
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $11.40
and payment in 5 WEEKS of $8.00")] <- 0
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $15.20
and payment in 5 WEEKS of $4.00")] <- 0
ctbdata_all$Today[which(ctbdata_all$Today == "Payment TODAY of $19.00
and payment in 5 WEEKS of $0")] <- 1
##5_weeks (correct answer denoted by 1)
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $3.80
and payment in 5 WEEKS of $16.00")] <- 0
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $7.60
and payment in 5 WEEKS of $12.00")] <- 0
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $11.40
and payment in 5 WEEKS of $8.00")] <- 0
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $15.20
and payment in 5 WEEKS of $4.00")] <- 0
ctbdata_all$X5.weeks[which(ctbdata_all$X5.weeks == "Payment TODAY of $19.00
and payment in 5 WEEKS of $0")] <- 0
##total (correct answer denoted by 1)
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $3.80
and payment in 5 WEEKS of $16.00")] <- 0
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $7.60
and payment in 5 WEEKS of $12.00")] <- 0
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $11.40
and payment in 5 WEEKS of $8.00")] <- 0
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $15.20
and payment in 5 WEEKS of $4.00")] <- 0
ctbdata_all$Total[which(ctbdata_all$Total == "Payment TODAY of $19.00
and payment in 5 WEEKS of $0")] <- 0
ctbdata_all$Relation <- as.numeric(ctbdata_all$Relation)
ctbdata_all$Today <- as.numeric(ctbdata_all$Today)
ctbdata_all$X5.weeks <- as.numeric(ctbdata_all$X5.weeks)
ctbdata_all$Total <- as.numeric(ctbdata_all$Total)
ctbdata_all$totalcorrect <- ctbdata_all$Relation + ctbdata_all$Today + ctbdata_all$X5.weeks + ctbdata_all$Total
ctbdata_all$totalcorrect <- as.numeric(ctbdata_all$totalcorrect)

#self-reported 
##transform (make text into numeric and reverse 10-0 scale)
ctbdata_all$Pat0.10[which(ctbdata_all$Pat0.10 == "Very
willing
to do so
10
")] <- 10
ctbdata_all$Pat0.10[which(ctbdata_all$Pat0.10 == "Completely
unwilling
to do so
0
")] <- 0
ctbdata_all$Pat0.10 <- as.numeric(ctbdata_all$Pat0.10)
ctbdata_all$Risk0.10[which(ctbdata_all$Risk0.10 == "Very
willing
to take risks
10
")] <- 10
ctbdata_all$Risk0.10[which(ctbdata_all$Risk0.10 == "Completely
unwilling
to take risks
0
")] <- 0
ctbdata_all$Risk0.10 <- as.numeric(ctbdata_all$Risk0.10)
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "Very
willing
to do so
0
")] <- 10
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "Completely
unwilling
to do so
10
")] <- 0
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "1")] <- "nine"
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "2")] <- "eight"
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "3")] <- "seven"
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "4")] <- "six"
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "6")] <- 4
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "7")] <- 3
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "8")] <- 2
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "9")] <- 1
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "nine")] <- 9
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "eight")] <- 8
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "seven")] <- 7
ctbdata_all$Pat10.0[which(ctbdata_all$Pat10.0 == "six")] <- 6 
ctbdata_all$Pat10.0 <- as.numeric(ctbdata_all$Pat10.0)
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "Very
willing
to take risks
0
")] <- 10
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "Completely
unwilling
to take risks
10
")] <- 0
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "1")] <- "nine"
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "2")] <- "eight"
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "3")] <- "seven"
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "4")] <- "six"
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "6")] <- 4
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "7")] <- 3
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "8")] <- 2
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "9")] <- 1
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "nine")] <- 9
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "eight")] <- 8
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "seven")] <- 7
ctbdata_all$Risk10.0[which(ctbdata_all$Risk10.0 == "six")] <- 6 
ctbdata_all$Risk10.0 <- as.numeric(ctbdata_all$Risk10.0)
##combine (make NA=0 and add 0-10 and 10-0 options)
ctbdata_all$Pat0.10[which(is.na(ctbdata_all$Pat0.10) == TRUE)] <- 0
ctbdata_all$Risk0.10[which(is.na(ctbdata_all$Risk0.10) == TRUE)] <- 0
ctbdata_all$Pat10.0[which(is.na(ctbdata_all$Pat10.0) == TRUE)] <- 0
ctbdata_all$Risk10.0[which(is.na(ctbdata_all$Risk10.0) == TRUE)] <- 0
ctbdata_all$Pat <- ctbdata_all$Pat0.10 + ctbdata_all$Pat10.0
ctbdata_all$Pat <- as.numeric(ctbdata_all$Pat)
ctbdata_all$Risk <- ctbdata_all$Risk0.10 + ctbdata_all$Risk10.0
ctbdata_all$Risk <- as.numeric(ctbdata_all$Risk)
ctbdata <- subset(ctbdata_all, select=c("ID", "Duration", "X5.1", "Timing.last", "Timing.submit", "X5.2", "Timing.last.1", "Timing.submit.1", "X5.3", "Timing.last.2", "Timing.submit.2", "X5.4", "Timing.last.3", "Timing.submit.3", "X5.5", "Timing.last.4", "Timing.submit.4", "X5.6", "Timing.last.5", "Timing.submit.5", "X9.1", "Timing.last.6", "Timing.submit.6", "X9.2", "Timing.last.7", "Timing.submit.7", "X9.3", "Timing.last.8", "Timing.submit.8", "X9.4", "Timing.last.9", "Timing.submit.9", "X9.5", "Timing.last.10", "Timing.submit.10", "X9.6", "Timing.last.11", "Timing.submit.11", "X5.10.1", "Timing.last.12", "Timing.submit.12", "X5.10.2", "Timing.last.13", "Timing.submit.13", "X5.10.3", "Timing.last.14", "Timing.submit.14", "X5.10.4", "Timing.last.15", "Timing.submit.15", "X5.10.5", "Timing.last.16", "Timing.submit.16", "X5.10.6", "Timing.last.17", "Timing.submit.17", "X5.14.1", "Timing.last.18", "Timing.submit.18", "X5.14.2", "Timing.last.19", "Timing.submit.19", "X5.14.3", "Timing.last.20", "Timing.submit.20", "X5.14.4", "Timing.last.21", "Timing.submit.21", "X5.14.5", "Timing.last.22", "Timing.submit.22", "X5.14.6", "Timing.last.23", "Timing.submit.23", "Relation", "Today", "X5.weeks", "Total", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Rising.temperatures", "More.add", "Less.add", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "totalcorrect", "Pat", "Risk"))
##high (binary = 1 if above median)
ctbdata$Pat.high <- ctbdata$Pat
ctbdata$Pat.high[which(ctbdata$Pat.high <= 7)] <- 0
ctbdata$Pat.high[which(ctbdata$Pat.high > 7)] <- 1
ctbdata$Pat.high <- as.factor(ctbdata$Pat.high)

#ctb 
##rename (assign factor values to answer descriptions)
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $3.80
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $7.60
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $11.40
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $15.20
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.1[which(ctbdata$X5.1 == "Payment TODAY of $19.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.1 <- as.numeric(ctbdata$X5.1)
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $3.60
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $7.20
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $10.80
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $14.40
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.2[which(ctbdata$X5.2 == "Payment TODAY of $18.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.2 <- as.numeric(ctbdata$X5.2)
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $3.40
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $6.80
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $10.20
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $13.60
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.3[which(ctbdata$X5.3 == "Payment TODAY of $17.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.3 <- as.numeric(ctbdata$X5.3)
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $3.20
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $6.40
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $9.60
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $12.80
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.4[which(ctbdata$X5.4 == "Payment TODAY of $16.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.4 <- as.numeric(ctbdata$X5.4)
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $2.80
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $5.60
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $8.40
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $11.20
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.5[which(ctbdata$X5.5 == "Payment TODAY of $14.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.5 <- as.numeric(ctbdata$X5.5)
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $0
and payment in 5 WEEKS of $20.00")] <- 1
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $2.20
and payment in 5 WEEKS of $16.00")] <- 2
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $4.40
and payment in 5 WEEKS of $12.00")] <- 3
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $6.60
and payment in 5 WEEKS of $8.00")] <- 4
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $8.80
and payment in 5 WEEKS of $4.00")] <- 5
ctbdata$X5.6[which(ctbdata$X5.6 == "Payment TODAY of $11.00
and payment in 5 WEEKS of $0")] <- 6
ctbdata$X5.6 <- as.numeric(ctbdata$X5.6)
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $4.00
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $8.00
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $12.00
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $16.00
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.1[which(ctbdata$X9.1 == "Payment TODAY of $20.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.1 <- as.numeric(ctbdata$X9.1)
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $3.80
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $7.60
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $11.40
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $15.20
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.2[which(ctbdata$X9.2 == "Payment TODAY of $19.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.2 <- as.numeric(ctbdata$X9.2)
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $3.60
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $7.20
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $10.80
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $14.40
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.3[which(ctbdata$X9.3 == "Payment TODAY of $17.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.3 <- as.numeric(ctbdata$X9.3)
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $3.00
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $6.00
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $9.00
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $12.00
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.4[which(ctbdata$X9.4 == "Payment TODAY of $15.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.4 <- as.numeric(ctbdata$X9.4)
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $2.40
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $4.80
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $7.20
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $9.60
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.5[which(ctbdata$X9.5 == "Payment TODAY of $12.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.5 <- as.numeric(ctbdata$X9.5)
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $0
and payment in 9 WEEKS of $20.00")] <- 1
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $1.80
and payment in 9 WEEKS of $16.00")] <- 2
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $3.60
and payment in 9 WEEKS of $12.00")] <- 3
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $5.40
and payment in 9 WEEKS of $8.00")] <- 4
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $7.20
and payment in 9 WEEKS of $4.00")] <- 5
ctbdata$X9.6[which(ctbdata$X9.6 == "Payment TODAY of $9.00
and payment in 9 WEEKS of $0")] <- 6
ctbdata$X9.6 <- as.numeric(ctbdata$X9.6)
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $3.80
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $7.60
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $11.40
and payment in 10 WEEKS of $8.00")] <- 4
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $15.20
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.1[which(ctbdata$X5.10.1 == "Payment in 5 WEEKS of $19.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.1 <- as.numeric(ctbdata$X5.10.1)
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $3.60
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $7.20
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $10.80
and payment in 10 WEEKS of $8.0")] <- 4
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $14.40
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.2[which(ctbdata$X5.10.2 == "Payment in 5 WEEKS of $18.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.2 <- as.numeric(ctbdata$X5.10.2)
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $3.40
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $6.80
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $10.20
and payment in 10 WEEKS of $8.00")] <- 4
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $13.60
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.3[which(ctbdata$X5.10.3 == "Payment in 5 WEEKS of $17.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.3 <- as.numeric(ctbdata$X5.10.3)
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $3.20
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $6.40
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $9.60
and payment in 10 WEEKS of $8.00")] <- 4
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $12.80
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.4[which(ctbdata$X5.10.4 == "Payment in 5 WEEKS of $16.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.4 <- as.numeric(ctbdata$X5.10.4)
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $2.80
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $5.60
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $8.40
and payment in 10 WEEKS of $8.00")] <- 4
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $11.20
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.5[which(ctbdata$X5.10.5 == "Payment in 5 WEEKS of $14.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.5 <- as.numeric(ctbdata$X5.10.5)
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $0
and payment in 10 WEEKS of $20.00")] <- 1
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $2.20
and payment in 10 WEEKS of $16.00")] <- 2
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $4.40
and payment in 10 WEEKS of $12.00")] <- 3
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $6.60
and payment in 10 WEEKS of $8.00")] <- 4
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $8.80
and payment in 10 WEEKS of $4.00")] <- 5
ctbdata$X5.10.6[which(ctbdata$X5.10.6 == "Payment in 5 WEEKS of $11.00
and payment in 10 WEEKS of $0")] <- 6
ctbdata$X5.10.6 <- as.numeric(ctbdata$X5.10.6)
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $4.00
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $8.00
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $12.00
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $16.00
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.1[which(ctbdata$X5.14.1 == "Payment in 5 WEEKS of $20.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.1 <- as.numeric(ctbdata$X5.14.1)
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $3.80
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $7.60
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $11.40
and payment in 14 WEEKS of $8.0")] <- 4
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $11.40
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $15.20
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.2[which(ctbdata$X5.14.2 == "Payment in 5 WEEKS of $19.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.2 <- as.numeric(ctbdata$X5.14.2)
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $3.60
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $7.20
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $10.80
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $14.40
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.3[which(ctbdata$X5.14.3 == "Payment in 5 WEEKS of $17.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.3 <- as.numeric(ctbdata$X5.14.3)
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $3.00
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $6.00
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $9.00
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $12.00
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.4[which(ctbdata$X5.14.4 == "Payment in 5 WEEKS of $15.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.4 <- as.numeric(ctbdata$X5.14.4)
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $2.40
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $4.80
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $7.20
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $9.60
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.5[which(ctbdata$X5.14.5 == "Payment in 5 WEEKS of $12.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.5 <- as.numeric(ctbdata$X5.14.5)
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $0
and payment in 14 WEEKS of $20.00")] <- 1
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $1.80
and payment in 14 WEEKS of $16.00")] <- 2
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $3.60
and payment in 14 WEEKS of $12.00")] <- 3
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $5.40
and payment in 14 WEEKS of $8.00")] <- 4
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $7.20
and payment in 14 WEEKS of $4.00")] <- 5
ctbdata$X5.14.6[which(ctbdata$X5.14.6 == "Payment in 5 WEEKS of $9.00
and payment in 14 WEEKS of $0")] <- 6
ctbdata$X5.14.6 <- as.numeric(ctbdata$X5.14.6)

#policy (binary where strongly agree or agree = 1)
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Strongly
Agree")] <- 1
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "StronglyAgree")] <- 1
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Agree")] <- 1
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Neither Agree nor Disagree")] <- 0
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Disagree")] <- 0
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Strongly
Disagree")] <- 0
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "StronglyDisgree")] <- 0
ctbdata$GHG.emissions[which(ctbdata$GHG.emissions == "Don'tKnow")] <- NA
ctbdata$GHG.emissions <- as.numeric(ctbdata$GHG.emissions)
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Strongly
Agree")] <- 1
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "StronglyAgree")] <- 1
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Agree")] <- 1
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Neither Agree nor Disagree")] <- 0
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Disagree")] <- 0
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Strongly
Disagree")] <- 0
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "StronglyDisgree")] <- 0
ctbdata$Carbon.tech[which(ctbdata$Carbon.tech == "Don'tKnow")] <- NA
ctbdata$Carbon.tech <- as.numeric(ctbdata$Carbon.tech)
ctbdata$Public.spending[which(ctbdata$Public.spending == "Strongly
Agree")] <- 1
ctbdata$Public.spending[which(ctbdata$Public.spending == "StronglyAgree")] <- 1
ctbdata$Public.spending[which(ctbdata$Public.spending == "Agree")] <- 1
ctbdata$Public.spending[which(ctbdata$Public.spending == "Neither Agree nor Disagree")] <- 0
ctbdata$Public.spending[which(ctbdata$Public.spending == "Disagree")] <- 0
ctbdata$Public.spending[which(ctbdata$Public.spending == "Strongly
Disagree")] <- 0
ctbdata$Public.spending[which(ctbdata$Public.spending == "StronglyDisgree")] <- 0
ctbdata$Public.spending[which(ctbdata$Public.spending == "Don'tKnow")] <- NA
ctbdata$Public.spending <- as.numeric(ctbdata$Public.spending)
ctbdata$Human.capital[which(ctbdata$Human.capital == "Strongly
Agree")] <- 1
ctbdata$Human.capital[which(ctbdata$Human.capital == "StronglyAgree")] <- 1
ctbdata$Human.capital[which(ctbdata$Human.capital == "Agree")] <- 1
ctbdata$Human.capital[which(ctbdata$Human.capital == "Neither Agree nor Disagree")] <- 0
ctbdata$Human.capital[which(ctbdata$Human.capital == "Disagree")] <- 0
ctbdata$Human.capital[which(ctbdata$Human.capital == "Strongly
Disagree")] <- 0
ctbdata$Human.capital[which(ctbdata$Human.capital == "StronglyDisgree")] <- 0
ctbdata$Human.capital[which(ctbdata$Human.capital == "Don'tKnow")] <- NA
ctbdata$Human.capital <- as.numeric(ctbdata$Human.capital)
ctbdata$Gender.military[which(ctbdata$Gender.military == "Strongly
Agree")] <- 1
ctbdata$Gender.military[which(ctbdata$Gender.military == "StronglyAgree")] <- 1
ctbdata$Gender.military[which(ctbdata$Gender.military == "Agree")] <- 1
ctbdata$Gender.military[which(ctbdata$Gender.military == "Neither Agree nor Disagree")] <- 0
ctbdata$Gender.military[which(ctbdata$Gender.military == "Disagree")] <- 0
ctbdata$Gender.military[which(ctbdata$Gender.military == "Strongly
Disagree")] <- 0
ctbdata$Gender.military[which(ctbdata$Gender.military == "StronglyDisgree")] <- 0
ctbdata$Gender.military[which(ctbdata$Gender.military == "Don'tKnow")] <- NA
ctbdata$Gender.military <- as.numeric(ctbdata$Gender.military)

#gss (binary where thinking there's too little action = 1)
ctbdata$Environment[which(ctbdata$Environment == "Too little")] <- 1
ctbdata$Environment[which(ctbdata$Environment == "About right")] <- 0
ctbdata$Environment[which(ctbdata$Environment == "Too much")] <- 0
ctbdata$Environment[which(ctbdata$Environment == "Don't know")] <- NA
ctbdata$Environment <- as.numeric(ctbdata$Environment)
ctbdata$Mass.transportation[which(ctbdata$Mass.transportation == "Too little")] <- 1
ctbdata$Mass.transportation[which(ctbdata$Mass.transportation == "About right")] <- 0
ctbdata$Mass.transportation[which(ctbdata$Mass.transportation == "Too much")] <- 0
ctbdata$Mass.transportation[which(ctbdata$Mass.transportation == "Don't know")] <- NA
ctbdata$Mass.transportation <- as.numeric(ctbdata$Mass.transportation)
ctbdata$Alternative.energy[which(ctbdata$Alternative.energy == "Too little")] <- 1
ctbdata$Alternative.energy[which(ctbdata$Alternative.energy == "About right")] <- 0
ctbdata$Alternative.energy[which(ctbdata$Alternative.energy == "Too much")] <- 0
ctbdata$Alternative.energy[which(ctbdata$Alternative.energy == "Don't know")] <- NA
ctbdata$Alternative.energy <- as.numeric(ctbdata$Alternative.energy)

#anes (binary where thinking we should be doing more = 1)
ctbdata$Rising.temperaturesMORE <- paste(ctbdata$Rising.temperatures, ctbdata$More.add) 
ctbdata$Rising.temperature <- paste(ctbdata$Rising.temperaturesMORE, ctbdata$Less.add)
ctbdata <- subset(ctbdata, select=c("ID", "Duration", "X5.1", "Timing.last", "Timing.submit", "X5.2", "Timing.last.1", "Timing.submit.1", "X5.3", "Timing.last.2", "Timing.submit.2", "X5.4", "Timing.last.3", "Timing.submit.3", "X5.5", "Timing.last.4", "Timing.submit.4", "X5.6", "Timing.last.5", "Timing.submit.5", "X9.1", "Timing.last.6", "Timing.submit.6", "X9.2", "Timing.last.7", "Timing.submit.7", "X9.3", "Timing.last.8", "Timing.submit.8", "X9.4", "Timing.last.9", "Timing.submit.9", "X9.5", "Timing.last.10", "Timing.submit.10", "X9.6", "Timing.last.11", "Timing.submit.11", "X5.10.1", "Timing.last.12", "Timing.submit.12", "X5.10.2", "Timing.last.13", "Timing.submit.13", "X5.10.3", "Timing.last.14", "Timing.submit.14", "X5.10.4", "Timing.last.15", "Timing.submit.15", "X5.10.5", "Timing.last.16", "Timing.submit.16", "X5.10.6", "Timing.last.17", "Timing.submit.17", "X5.14.1", "Timing.last.18", "Timing.submit.18", "X5.14.2", "Timing.last.19", "Timing.submit.19", "X5.14.3", "Timing.last.20", "Timing.submit.20", "X5.14.4", "Timing.last.21", "Timing.submit.21", "X5.14.5", "Timing.last.22", "Timing.submit.22", "X5.14.6", "Timing.last.23", "Timing.submit.23", "Relation", "Today", "X5.weeks", "Total", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "totalcorrect", "Pat", "Risk", "Pat.high", "Rising.temperature"))
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing more A great deal ")] <- 1
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing more A moderate amount ")] <- 1
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing more A little ")] <- 1
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Is currently doing the right amount  ")] <- 0
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing less  A little")] <- 0
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing less  A moderate amount")] <- 0
ctbdata$Rising.temperature[which(ctbdata$Rising.temperature == "Should be doing less  A great deal")] <- 0
ctbdata$Rising.temperature <- as.numeric(ctbdata$Rising.temperature)

ctbdataR <- ctbdata[which(is.na(ctbdata$Timing.last) == FALSE),]

#corner options (sum factors denoting CTB answers to identify those who only selected corner options)
ctbdataR$totCTB <- ctbdataR$X5.1 + ctbdataR$X5.2 + ctbdataR$X5.3 + ctbdataR$X5.4 + ctbdataR$X5.5 + ctbdataR$X5.6 + ctbdataR$X9.1 + ctbdataR$X9.2 + ctbdataR$X9.3 + ctbdataR$X9.4 + ctbdataR$X9.5 + ctbdataR$X9.6 + ctbdataR$X5.10.1 + ctbdataR$X5.10.2 + ctbdataR$X5.10.3 + ctbdataR$X5.10.4 + ctbdataR$X5.10.5 + ctbdataR$X5.10.6 + ctbdataR$X5.14.1 + ctbdataR$X5.14.2 + ctbdataR$X5.14.3 + ctbdataR$X5.14.4 + ctbdataR$X5.14.5 + ctbdataR$X5.14.6
ctbdataR$corner <- ctbdataR$totCTB
ctbdataR$corner[which(ctbdataR$corner == 144)] <- 1
ctbdataR$corner[which(ctbdataR$corner == 24)] <- 1
ctbdataR$corner[which(ctbdataR$corner != 1)] <- 0
ctbdataR <- subset(ctbdataR, select=c("ID", "Duration", "X5.1", "Timing.last", "Timing.submit", "X5.2", "Timing.last.1", "Timing.submit.1", "X5.3", "Timing.last.2", "Timing.submit.2", "X5.4", "Timing.last.3", "Timing.submit.3", "X5.5", "Timing.last.4", "Timing.submit.4", "X5.6", "Timing.last.5", "Timing.submit.5", "X9.1", "Timing.last.6", "Timing.submit.6", "X9.2", "Timing.last.7", "Timing.submit.7", "X9.3", "Timing.last.8", "Timing.submit.8", "X9.4", "Timing.last.9", "Timing.submit.9", "X9.5", "Timing.last.10", "Timing.submit.10", "X9.6", "Timing.last.11", "Timing.submit.11", "X5.10.1", "Timing.last.12", "Timing.submit.12", "X5.10.2", "Timing.last.13", "Timing.submit.13", "X5.10.3", "Timing.last.14", "Timing.submit.14", "X5.10.4", "Timing.last.15", "Timing.submit.15", "X5.10.5", "Timing.last.16", "Timing.submit.16", "X5.10.6", "Timing.last.17", "Timing.submit.17", "X5.14.1", "Timing.last.18", "Timing.submit.18", "X5.14.2", "Timing.last.19", "Timing.submit.19", "X5.14.3", "Timing.last.20", "Timing.submit.20", "X5.14.4", "Timing.last.21", "Timing.submit.21", "X5.14.5", "Timing.last.22", "Timing.submit.22", "X5.14.6", "Timing.last.23", "Timing.submit.23", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "Pat", "Risk", "Pat.high", "Rising.temperature", "corner"))
##timing frequencies (combine timing last and timing submit values across all CTB questions for each respondent)
timing_lastR <- c(ctbdataR$Timing.last, ctbdataR$Timing.last.1, ctbdataR$Timing.last.2, ctbdataR$Timing.last.3, ctbdataR$Timing.last.4, ctbdataR$Timing.last.5, ctbdataR$Timing.last.6, ctbdataR$Timing.last.7, ctbdataR$Timing.last.8, ctbdataR$Timing.last.9, ctbdataR$Timing.last.10, ctbdataR$Timing.last.11, ctbdataR$Timing.last.12, ctbdataR$Timing.last.13, ctbdataR$Timing.last.14, ctbdataR$Timing.last.15, ctbdataR$Timing.last.16, ctbdataR$Timing.last.17, ctbdataR$Timing.last.18, ctbdataR$Timing.last.19, ctbdataR$Timing.last.20, ctbdataR$Timing.last.21, ctbdataR$Timing.last.22, ctbdataR$Timing.last.23)
timing_submitR <- c(ctbdataR$Timing.submit, ctbdataR$Timing.submit.1, ctbdataR$Timing.submit.2, ctbdataR$Timing.submit.3, ctbdataR$Timing.submit.4, ctbdataR$Timing.submit.5, ctbdataR$Timing.submit.6, ctbdataR$Timing.submit.7, ctbdataR$Timing.submit.8, ctbdataR$Timing.submit.9, ctbdataR$Timing.submit.10, ctbdataR$Timing.submit.11, ctbdataR$Timing.submit.12, ctbdataR$Timing.submit.13, ctbdataR$Timing.submit.14, ctbdataR$Timing.submit.15, ctbdataR$Timing.submit.16, ctbdataR$Timing.submit.17, ctbdataR$Timing.submit.18, ctbdataR$Timing.submit.19, ctbdataR$Timing.submit.20, ctbdataR$Timing.submit.21, ctbdataR$Timing.submit.22, ctbdataR$Timing.submit.23)
##trim (remove those who selected only corner options)
ctbdataRtrim <- ctbdataR[ which(ctbdataR$corner == 0), ]
ctbdataRtrim <- subset(ctbdataRtrim, select=c("ID", "Duration", "X5.1", "Timing.last", "Timing.submit", "X5.2", "Timing.last.1", "Timing.submit.1", "X5.3", "Timing.last.2", "Timing.submit.2", "X5.4", "Timing.last.3", "Timing.submit.3", "X5.5", "Timing.last.4", "Timing.submit.4", "X5.6", "Timing.last.5", "Timing.submit.5", "X9.1", "Timing.last.6", "Timing.submit.6", "X9.2", "Timing.last.7", "Timing.submit.7", "X9.3", "Timing.last.8", "Timing.submit.8", "X9.4", "Timing.last.9", "Timing.submit.9", "X9.5", "Timing.last.10", "Timing.submit.10", "X9.6", "Timing.last.11", "Timing.submit.11", "X5.10.1", "Timing.last.12", "Timing.submit.12", "X5.10.2", "Timing.last.13", "Timing.submit.13", "X5.10.3", "Timing.last.14", "Timing.submit.14", "X5.10.4", "Timing.last.15", "Timing.submit.15", "X5.10.5", "Timing.last.16", "Timing.submit.16", "X5.10.6", "Timing.last.17", "Timing.submit.17", "X5.14.1", "Timing.last.18", "Timing.submit.18", "X5.14.2", "Timing.last.19", "Timing.submit.19", "X5.14.3", "Timing.last.20", "Timing.submit.20", "X5.14.4", "Timing.last.21", "Timing.submit.21", "X5.14.5", "Timing.last.22", "Timing.submit.22", "X5.14.6", "Timing.last.23", "Timing.submit.23", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "Pat", "Risk", "Pat.high", "Rising.temperature"))

#+++++++++++++++++++++++++++++++++++
#
#+++++++++++++++++++++++++++++++++++

#reshape data from wide/horizontal to long/vertical
ctbdataRtrimRS <- reshape(ctbdataRtrim, 
                          varying = c("X5.1", "X5.2", "X5.3", "X5.4", "X5.5", "X5.6", "X9.1", "X9.2", "X9.3", "X9.4", "X9.5", "X9.6", "X5.10.1", "X5.10.2", "X5.10.3", "X5.10.4", "X5.10.5", "X5.10.6", "X5.14.1", "X5.14.2", "X5.14.3", "X5.14.4", "X5.14.5", "X5.14.6"), 
                          v.names = "Choice",
                          timevar = "Round", 
                          times = c("X5.1", "X5.2", "X5.3", "X5.4", "X5.5", "X5.6", "X9.1", "X9.2", "X9.3", "X9.4", "X9.5", "X9.6", "X5.10.1", "X5.10.2", "X5.10.3", "X5.10.4", "X5.10.5", "X5.10.6", "X5.14.1", "X5.14.2", "X5.14.3", "X5.14.4", "X5.14.5", "X5.14.6"), 
                          new.row.names = 1:52056,
                          direction = "long")
ctbdataRtrimRS <- subset(ctbdataRtrimRS, select=c("Duration", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "Pat", "Risk", "Pat.high", "Rising.temperature", "Round", "Choice", "id"))

#create variables needed to calculate patience (for timing, price ratio, and allocation ratio)
##chosen payout in sooner period
ctbdataRtrimRS$CTB.priceCHOtod <- paste(ctbdataRtrimRS$Round, ctbdataRtrimRS$Choice) 
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 2")] <- 3.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 3")] <- 7.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 4")] <- 11.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 5")] <- 15.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.1 6")] <- 19
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 2")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 3")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 4")] <- 10.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 5")] <- 14.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.2 6")] <- 18
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 2")] <- 3.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 3")] <- 6.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 4")] <- 10.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 5")] <- 13.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.3 6")] <- 17
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 2")] <- 3.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 3")] <- 6.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 4")] <- 9.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 5")] <- 12.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.4 6")] <- 16
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 2")] <- 2.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 3")] <- 5.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 4")] <- 8.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 5")] <- 11.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.5 6")] <- 14
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 2")] <- 2.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 3")] <- 4.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 4")] <- 6.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 5")] <- 8.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.6 6")] <- 11
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 2")] <- 4
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 3")] <- 8
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 4")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 5")] <- 16
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.1 6")] <- 20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 2")] <- 3.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 3")] <- 7.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 4")] <- 11.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 5")] <- 15.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.2 6")] <- 19
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 2")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 3")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 4")] <- 10.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 5")] <- 14.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.3 6")] <- 17
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 2")] <- 3
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 3")] <- 6
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 4")] <- 9
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 5")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.4 6")] <- 15
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 2")] <- 2.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 3")] <- 4.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 4")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 5")] <- 9.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.5 6")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 2")] <- 1.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 3")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 4")] <- 5.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 5")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X9.6 6")] <- 9
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 1")] <- 0 
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 2")] <- 3.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 3")] <- 7.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 4")] <- 11.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 5")] <- 15.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.1 6")] <- 19
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 2")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 3")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 4")] <- 10.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 5")] <- 14.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.2 6")] <- 18
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 2")] <- 3.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 3")] <- 6.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 4")] <- 10.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 5")] <- 13.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.3 6")] <- 17
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 2")] <- 3.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 3")] <- 6.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 4")] <- 9.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 5")] <- 12.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.4 6")] <- 16
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 2")] <- 2.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 3")] <- 5.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 4")] <- 8.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 5")] <- 11.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.5 6")] <- 14
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 2")] <- 2.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 3")] <- 4.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 4")] <- 6.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 5")] <- 8.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.10.6 6")] <- 11
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 2")] <- 4
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 3")] <- 8
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 4")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 5")] <- 16
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.1 6")] <- 20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 2")] <- 3.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 3")] <- 7.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 4")] <- 11.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 5")] <- 15.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.2 6")] <- 19
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 2")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 3")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 4")] <- 10.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 5")] <- 14.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.3 6")] <- 17
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 2")] <- 3
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 3")] <- 6
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 4")] <- 9
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 5")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.4 6")] <- 15
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 2")] <- 2.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 3")] <- 4.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 4")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 5")] <- 9.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.5 6")] <- 12
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 1")] <- 0
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 2")] <- 1.80
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 3")] <- 3.60
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 4")] <- 5.40
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 5")] <- 7.20
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == "X5.14.6 6")] <- 9
ctbdataRtrimRS$CTB.priceCHOtod[which(ctbdataRtrimRS$CTB.priceCHOtod == 0)] <- 0.001
ctbdataRtrimRS$CTB.priceCHOtod <- as.numeric(ctbdataRtrimRS$CTB.priceCHOtod)
##chosen payout in later period
ctbdataRtrimRS$CTB.priceCHOlat <- paste(ctbdataRtrimRS$Round, ctbdataRtrimRS$Choice)
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.1 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.2 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.3 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.4 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.5 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.6 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.1 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.2 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.3 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.4 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.5 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X9.6 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 1")] <- 20 
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.1 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.2 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.3 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.4 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.5 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.10.6 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.1 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.2 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.3 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.4 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.5 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 1")] <- 20
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 2")] <- 16
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 3")] <- 12
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 4")] <- 8
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 5")] <- 4
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == "X5.14.6 6")] <- 0
ctbdataRtrimRS$CTB.priceCHOlat[which(ctbdataRtrimRS$CTB.priceCHOlat == 0)] <- 0.001
ctbdataRtrimRS$CTB.priceCHOlat <- as.numeric(ctbdataRtrimRS$CTB.priceCHOlat)
##highest possible payout in later period
ctbdataRtrimRS$CTB.priceEXThighLAT <- ctbdataRtrimRS$Round
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.1")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.2")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.3")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.4")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.5")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.6")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.1")] <- 20 
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.2")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.3")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.4")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.5")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X9.6")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.1")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.2")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.3")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.4")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.5")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.10.6")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.1")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.2")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.3")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.4")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.5")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT[which(ctbdataRtrimRS$CTB.priceEXThighLAT == "X5.14.6")] <- 20
ctbdataRtrimRS$CTB.priceEXThighLAT <- as.numeric(ctbdataRtrimRS$CTB.priceEXThighLAT)
##highest possible payout in sooner period
ctbdataRtrimRS$CTB.priceEXThighTOD <- ctbdataRtrimRS$Round
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.1")] <- 19
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.2")] <- 18
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.3")] <- 17
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.4")] <- 16
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.5")] <- 14
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.6")] <- 11
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.1")] <- 20
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.2")] <- 19
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.3")] <- 17
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.4")] <- 15
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.5")] <- 12
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X9.6")] <- 9
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.1")] <- 19
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.2")] <- 18
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.3")] <- 17
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.4")] <- 16
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.5")] <- 14
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.10.6")] <- 11
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.1")] <- 20
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.2")] <- 19
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.3")] <- 17
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.4")] <- 15
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.5")] <- 12
ctbdataRtrimRS$CTB.priceEXThighTOD[which(ctbdataRtrimRS$CTB.priceEXThighTOD == "X5.14.6")] <- 9
ctbdataRtrimRS$CTB.priceEXThighTOD <- as.numeric(ctbdataRtrimRS$CTB.priceEXThighTOD)
##present period indicator
ctbdataRtrimRS$CTB.daysoon <- ctbdataRtrimRS$Round
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.1")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.2")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.3")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.4")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.5")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.6")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.1")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.2")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.3")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.4")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.5")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X9.6")] <- 1
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.1")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.2")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.3")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.4")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.5")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.10.6")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.1")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.2")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.3")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.4")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.5")] <- 0
ctbdataRtrimRS$CTB.daysoon[which(ctbdataRtrimRS$CTB.daysoon == "X5.14.6")] <- 0
ctbdataRtrimRS$CTB.daysoon <- as.numeric(ctbdataRtrimRS$CTB.daysoon)
##days between two possible payout dates
ctbdataRtrimRS$CTB.dayfar <- ctbdataRtrimRS$Round
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.1")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.2")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.3")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.4")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.5")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.6")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.1")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.2")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.3")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.4")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.5")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X9.6")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.1")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.2")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.3")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.4")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.5")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.10.6")] <- 35
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.1")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.2")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.3")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.4")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.5")] <- 63
ctbdataRtrimRS$CTB.dayfar[which(ctbdataRtrimRS$CTB.dayfar == "X5.14.6")] <- 63
ctbdataRtrimRS$CTB.dayfar <- as.numeric(ctbdataRtrimRS$CTB.dayfar)

#+++++++++++++++++++++++++++++++++
#
#+++++++++++++++++++++++++++++++++

#Calculate patience and risk parameters for each participant (ln(allocation ratio) ~ number of days to first payment [t] + number of days to delayed payment [k] + ln(price ratio))
library(plyr)
linmod <- function(ctbdataRtrimRS) {
  lm(log(CTB.priceCHOtod/CTB.priceCHOlat) ~ CTB.daysoon + CTB.dayfar + log(CTB.priceEXThighLAT/CTB.priceEXThighTOD), ctbdataRtrimRS)
}
models <- dlply(ctbdataRtrimRS, .(id), linmod) 
CTB_coeff <- ldply(models, coef)
##d: exp(_b[k]/_b[ln_pratio])
CTB_coeff$patience <- exp(CTB_coeff$CTB.dayfar/CTB_coeff$`log(CTB.priceEXThighLAT/CTB.priceEXThighTOD)`)
##a: 1/_b[ln_pratio] + 1
CTB_coeff$risk <- 1/CTB_coeff$`log(CTB.priceEXThighLAT/CTB.priceEXThighTOD)` + 1
##b: exp(_b[t0]/_b[ln_pratio])
CTB_coeff$present <- exp(CTB_coeff$CTB.daysoon/CTB_coeff$`log(CTB.priceEXThighLAT/CTB.priceEXThighTOD)`)

#trim data (by removing patience measures above 95% and below 5%)
ctb_final <- merge(ctbdataRtrimRS,CTB_coeff,by="id")
ctb_finalTRIM <- ctb_final[which(ctb_final$patience > 0.9382021),]
ctb_finalTRIM <- ctb_finalTRIM[which(ctb_finalTRIM$patience < 1.0793351),]

#reshape data to be wide
ctbdata_final <- reshape(ctb_finalTRIM, idvar = "id", v.names="Choice", timevar = "Round", direction = "wide")
ctbdata_final <- subset(ctbdata_final, select=c("id", "Duration", "GHG.emissions", "Carbon.tech", "Public.spending", "Human.capital", "Gender.military", "Environment", "Mass.transportation", "Alternative.energy", "Water.pipe", "White", "Female", "Young", "Mid.Young", "Mid.Old", "Old", "Less.high", "High", "Some.college", "BA.plus", "Low.inc", "LowMid.inc", "UppMid.inc", "High.inc", "Pat", "Risk", "Pat.high", "Rising.temperature", "patience", "risk"))

#create variable for high patience (above median)
ctbdata_final$patience.high <- ctbdata_final$patience
ctbdata_final$patience.high[which(ctbdata_final$patience.high <= 0.9969159)] <- 0
ctbdata_final$patience.high[which(ctbdata_final$patience.high > 0.9969159)] <- 1
ctbdata_final$patience.high <- as.factor(ctbdata_final$patience.high)

# Table 3 (Public Policy)
##policy support (old & new ques ~ patience measure (CTB & stated, linear and binary [1 if above median] for both) + sociodemographic variables (age, education, income, gender, and race) + risk acceptance...robust SE clustered by respondent

#CTB GHG emissions (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_ghg <- lm(GHG.emissions ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_ghg <- lm(GHG.emissions ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported GHG emissions (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_ghg <- lm(GHG.emissions ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_ghg <- lm(GHG.emissions ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB carbon tech (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_tec <- lm(Carbon.tech ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_tec <- lm(Carbon.tech ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported carbon tech (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_tec <- lm(Carbon.tech ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_tec <- lm(Carbon.tech ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB public spending (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_pub <- lm(Public.spending ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_pub <- lm(Public.spending ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported public spending (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_pub <- lm(Public.spending ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_pub <- lm(Public.spending ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB human capital (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_hum <- lm(Human.capital ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_hum <- lm(Human.capital ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported human capital (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_hum <- lm(Human.capital ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_hum <- lm(Human.capital ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB gender military (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_gen <- lm(Gender.military ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_gen <- lm(Gender.military~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported gender military (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_gen <- lm(Gender.military ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_gen <- lm(Gender.military ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB environment (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_env <- lm(Environment ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_env <- lm(Environment~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported environment (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_env <- lm(Environment ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_env <- lm(Environment ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB mass transportation (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_tra <- lm(Mass.transportation ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_tra <- lm(Mass.transportation ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported mass transportation (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_tra <- lm(Mass.transportation ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_tra <- lm(Mass.transportation ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB alternative energy (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_alt <- lm(Alternative.energy ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_alt <- lm(Alternative.energy ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported alternative energy (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_alt <- lm(Alternative.energy ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_alt <- lm(Alternative.energy ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#CTB rising temperature (CTB with sociodemographics and CTB high with sociodemographics)
CTBpatPOLsocreg_tem <- lm(Rising.temperature ~ patience + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)
CTBpatPOLhighsocreg_tem <- lm(Rising.temperature ~ patience.high + risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdata_final)

#self-reported rising temperature (stated with sociodemographics and stated high with sociodemographics)
SRpatPOLsocreg_tem <- lm(Rising.temperature ~ Pat + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)
SRpatPOLhighsocreg_tem <- lm(Rising.temperature ~ Pat.high + Risk + White + Female + Mid.Young + Mid.Old + Old + High + Some.college + BA.plus + LowMid.inc + UppMid.inc + High.inc, ctbdataR)

#+++++++++++++++++++++++++++
# Tables
#+++++++++++++++++++++++++++

## fix for stargazer <= 5.2.3 is.na() issue with long model names in R >= 4.2
#install.packages("stargazer")
library("stargazer")
# Unload stargazer if loaded
detach("package:stargazer", character.only = TRUE)
# Delete it
remove.packages("stargazer")
# Download the source
download.file("https://cran.r-project.org/src/contrib/stargazer_5.2.3.tar.gz", destfile = "stargazer_5.2.3.tar.gz")
# Unpack
untar("stargazer_5.2.3.tar.gz")
# Read the sourcefile with .inside.bracket fun
stargazer_src <- readLines("stargazer/R/stargazer-internal.R")
# Move the length check 5 lines up so it precedes is.na(.)
stargazer_src[1990] <- stargazer_src[1995]
stargazer_src[1995] <- ""
# Save back
writeLines(stargazer_src, con="stargazer/R/stargazer-internal.R")
# Compile and install the patched package
install.packages("stargazer", repos = NULL, type="source")

#+++++++++++++++++++++++++++++
# Table A.8

#CTB old (create table for CTB effects on old policies)
library(sandwich)
library(plm)
library(stargazer)

cluster_se1 <- coef(summary(CTBpatPOLsocreg_ghg,cluster = c("id")))[, 2]
cluster_se2 <- coef(summary(CTBpatPOLhighsocreg_ghg,cluster = c("id")))[, 2]
cluster_se3 <- coef(summary(CTBpatPOLsocreg_tec,cluster = c("id")))[, 2]
cluster_se4 <- coef(summary(CTBpatPOLhighsocreg_tec,cluster = c("id")))[, 2]
cluster_se5 <- coef(summary(CTBpatPOLsocreg_hum,cluster = c("id")))[, 2]
cluster_se6 <- coef(summary(CTBpatPOLhighsocreg_hum,cluster = c("id")))[, 2]
cluster_se7 <- coef(summary(CTBpatPOLsocreg_pub,cluster = c("id")))[, 2]
cluster_se8 <- coef(summary(CTBpatPOLhighsocreg_pub,cluster = c("id")))[, 2]
cluster_se9 <- coef(summary(CTBpatPOLsocreg_gen,cluster = c("id")))[, 2]
cluster_se10 <- coef(summary(CTBpatPOLhighsocreg_gen,cluster = c("id")))[, 2]

stargazer(CTBpatPOLsocreg_ghg, CTBpatPOLhighsocreg_ghg, CTBpatPOLsocreg_tec, CTBpatPOLhighsocreg_tec, CTBpatPOLsocreg_hum, CTBpatPOLhighsocreg_hum, CTBpatPOLsocreg_pub, CTBpatPOLhighsocreg_pub, CTBpatPOLsocreg_gen, CTBpatPOLhighsocreg_gen, header=FALSE, style="ajps", omit=c("Constant", "risk", "White", "Female", "Mid.Young", "Mid.Old", "Old", "High", "Some.college", "BA.plus", "LowMid.inc", "UppMid.inc", "High.inc"), omit.stat=c("f", "ser", "ll", "wald", "adj.rsq"), title="Table A.8 (Patience CTB results)", column.labels = c("GHG", "GHG", "Tech", "Tech", "Human", "Human", "Spend", "Spend", "Gender", "Gender"), covariate.labels = c("Patience", "Patience (High)"), dep.var.labels.include = FALSE, model.names=FALSE, model.numbers=FALSE, se=list(cluster_se1, cluster_se2, cluster_se3, cluster_se4, cluster_se5, cluster_se6, cluster_se7, cluster_se8, cluster_se9, cluster_se10), digits=2, digits.extra=1, digit.separator=",", font.size="footnotesize", notes = c("Notes:", c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001")), star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001), notes.append=FALSE, out = "03 Results/TableA8_CTB.html")

#SR old (create table for stated effects on old policies)
library(sandwich)
library(plm)
library(stargazer)
cluster_se19 <- coef(summary(SRpatPOLsocreg_ghg,cluster = c("ID")))[, 2]
cluster_se20 <- coef(summary(SRpatPOLhighsocreg_ghg,cluster = c("ID")))[, 2]
cluster_se21 <- coef(summary(SRpatPOLsocreg_tec,cluster = c("ID")))[, 2]
cluster_se22 <- coef(summary(SRpatPOLhighsocreg_tec,cluster = c("ID")))[, 2]
cluster_se23 <- coef(summary(SRpatPOLsocreg_hum,cluster = c("ID")))[, 2]
cluster_se24 <- coef(summary(SRpatPOLhighsocreg_hum,cluster = c("ID")))[, 2]
cluster_se25 <- coef(summary(SRpatPOLsocreg_pub,cluster = c("ID")))[, 2]
cluster_se26 <- coef(summary(SRpatPOLhighsocreg_pub,cluster = c("ID")))[, 2]
cluster_se27 <- coef(summary(SRpatPOLsocreg_gen,cluster = c("ID")))[, 2]
cluster_se28 <- coef(summary(SRpatPOLhighsocreg_gen,cluster = c("ID")))[, 2]

stargazer(SRpatPOLsocreg_ghg, SRpatPOLhighsocreg_ghg, SRpatPOLsocreg_tec, SRpatPOLhighsocreg_tec, SRpatPOLsocreg_hum, SRpatPOLhighsocreg_hum, SRpatPOLsocreg_pub, SRpatPOLhighsocreg_pub, SRpatPOLsocreg_gen, SRpatPOLhighsocreg_gen, header=FALSE, style="ajps", omit=c("Risk", "White", "Female", "Mid.Young", "Mid.Old", "Old", "High", "Some.college", "BA.plus", "LowMid.inc", "UppMid.inc", "High.inc", "Constant"), omit.stat=c("f", "ser", "ll", "wald", "adj.rsq"), title="Table A.8 (Patience Stated results)", column.labels = c("GHG", "GHG", "Tech", "Tech", "Human", "Human", "Spend", "Spend", "Gender", "Gender"), covariate.labels = c("Patience", "Patience (High)"), dep.var.labels.include = FALSE, model.names=FALSE, model.numbers=FALSE, se=list(cluster_se19, cluster_se20, cluster_se21, cluster_se22, cluster_se23, cluster_se24, cluster_se25, cluster_se26, cluster_se27, cluster_se28), digits=2, digits.extra=1, digit.separator=",", font.size="footnotesize", notes = c("Notes:", c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001")), star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001), notes.append=FALSE, out = "03 Results/TableA8_Stated.html")

#++++++++++++++++++++++++++++++++++++++++++++++
# Table A.9

#CTB new (create table for CTB effects on new policies)
library(sandwich)
library(plm)
library(stargazer)
cluster_se11 <- coef(summary(CTBpatPOLsocreg_env,cluster = c("id")))[, 2]
cluster_se12 <- coef(summary(CTBpatPOLhighsocreg_env,cluster = c("id")))[, 2]
cluster_se13 <- coef(summary(CTBpatPOLsocreg_tra,cluster = c("id")))[, 2]
cluster_se14 <- coef(summary(CTBpatPOLhighsocreg_tra,cluster = c("id")))[, 2]
cluster_se15 <- coef(summary(CTBpatPOLsocreg_alt,cluster = c("id")))[, 2]
cluster_se16 <- coef(summary(CTBpatPOLhighsocreg_alt,cluster = c("id")))[, 2]
cluster_se17 <- coef(summary(CTBpatPOLsocreg_tem,cluster = c("id")))[, 2]
cluster_se18 <- coef(summary(CTBpatPOLhighsocreg_tem,cluster = c("id")))[, 2]
stargazer(CTBpatPOLsocreg_env, CTBpatPOLhighsocreg_env, CTBpatPOLsocreg_tra, CTBpatPOLhighsocreg_tra, CTBpatPOLsocreg_alt, CTBpatPOLhighsocreg_alt, CTBpatPOLsocreg_tem, CTBpatPOLhighsocreg_tem, header=FALSE, style="ajps", omit=c("risk", "White", "Female", "Mid.Young", "Mid.Old", "Old", "High", "Some.college", "BA.plus", "LowMid.inc", "UppMid.inc", "High.inc", "Constant"), omit.stat=c("f", "ser", "ll", "wald", "adj.rsq"), title="Table A.9 (Patience CTB results)", column.labels = c("Environ", "Environ", "Transport", "Transport", "Energy", "Energy", "Temp", "Temp"), covariate.labels = c("Patience", "Patience (High)"), dep.var.labels.include = FALSE, model.names=FALSE, model.numbers=FALSE, se=list(cluster_se11, cluster_se12, cluster_se13, cluster_se14, cluster_se15, cluster_se16, cluster_se17, cluster_se18), digits=2, digits.extra=1, digit.separator=",", font.size="footnotesize", notes = c("Notes:", c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001")), star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001), notes.append=FALSE, out = "03 Results/TableA9_CTB.html")

#SR new (create table for stated effects on new policies)
library(sandwich)
library(plm)
library(stargazer)
cluster_se29 <- coef(summary(SRpatPOLsocreg_env,cluster = c("ID")))[, 2]
cluster_se30 <- coef(summary(SRpatPOLhighsocreg_env,cluster = c("ID")))[, 2]
cluster_se31 <- coef(summary(SRpatPOLsocreg_tra,cluster = c("ID")))[, 2]
cluster_se32 <- coef(summary(SRpatPOLhighsocreg_tra,cluster = c("ID")))[, 2]
cluster_se33 <- coef(summary(SRpatPOLsocreg_alt,cluster = c("ID")))[, 2]
cluster_se34 <- coef(summary(SRpatPOLhighsocreg_alt,cluster = c("ID")))[, 2]
cluster_se35 <- coef(summary(SRpatPOLsocreg_tem,cluster = c("ID")))[, 2]
cluster_se36 <- coef(summary(SRpatPOLhighsocreg_tem,cluster = c("ID")))[, 2]
stargazer(SRpatPOLsocreg_env, SRpatPOLhighsocreg_env, SRpatPOLsocreg_tra, SRpatPOLhighsocreg_tra, SRpatPOLsocreg_alt, SRpatPOLhighsocreg_alt, SRpatPOLsocreg_tem, SRpatPOLhighsocreg_tem, header=FALSE, style="ajps", omit=c("Risk", "White", "Female", "Mid.Young", "Mid.Old", "Old", "High", "Some.college", "BA.plus", "LowMid.inc", "UppMid.inc", "High.inc", "Constant"), omit.stat=c("f", "ser", "ll", "wald", "adj.rsq"), title="Table A.9 (Patience Stated results)", column.labels = c("Environ", "Environ", "Transport", "Transport", "Energy", "Energy", "Temp", "Temp"), covariate.labels = c("Patience", "Patience (High)"), dep.var.labels.include = FALSE, model.names=FALSE, model.numbers=FALSE, se=list(cluster_se29, cluster_se30, cluster_se31, cluster_se32, cluster_se33, cluster_se34, cluster_se35, cluster_se36), digits=2, digits.extra=1, digit.separator=",", font.size="footnotesize", notes = c("Notes:", c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001")), star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001), notes.append=FALSE, out = "03 Results/TableA9_Stated.html")

#+++++++++++++++++++++++++++++
# Table A.13
ctbdata_all$Born <- as.factor(ctbdata_all$Born)
ctbdata_all$Education <- as.factor(ctbdata_all$Education)
#all
library(dplyr)
ctbdata_all %>% count(Born)/2955

a13_1 <- ctbdata_all %>% count(Born)/2955
a13_1 <- a13_1 %>% select(n)
names(a13_1) = c("Born (N)")
a13_2 <- ctbdata_all %>% count(Education)/2955 
a13_2 <- a13_2 %>% select(n)
names(a13_2) = c("Education (N)")
a13_3 <- ctbdata_all %>% count(Female)/2955 
a13_3 <- a13_3 %>% select(n)
names(a13_3) = c("Female (N)")

stargazer(a13_1, a13_2, summary=F,digits=7, out = "03 Results/TableA13_1.html") 
stargazer(a13_3, summary=F,digits=7, out = "03 Results/TableA13_2.html") 